const Koa=require('koa2');
const app=new Koa();
const body=require('koa-body');
const router=require('./router/router');
const cors = require('koa2-cors')
const https = require('https')
const fs = require('fs')
app.use(body({
    multipart:true,
    strict:false,
    formidable:{
        maxFileSize:200*1024*1024
    }
}))

app.use(cors({
    origin: function(ctx) { //设置允许来自指定域名请求
        return '*'; //只允许http://localhost:8080这个域名的请求
    },
    maxAge: 5, //指定本次预检请求的有效期，单位为秒。
    credentials: true, //是否允许发送Cookie
    allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], //设置所允许的HTTP请求方法'
    allowHeaders: ['Content-Type', 'Authorization', 'Accept'], //设置服务器支持的所有头信息字段
    exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'] //设置获取其他自定义字段
}))
app.use(router.routes(),router.allowedMethods());
let serv = https.createServer({
    cert: fs.readFileSync('./wx.original5.xyz.pem'),
    key: fs.readFileSync('./wx.original5.xyz.key'),
}, app.callback())

serv.listen(2003, '0.0.0.0');